package blue_bridge_cup_learning.前缀和;

import java.util.*;

public class 一维模板 {
    public static void main(String[] args) {
        int[] arr = { 0, 1, 2, 3, 4, 5 };
        int[] add_arr = new int[arr.length];
        for (int i = 1; i < arr.length; i++) {
            add_arr[i] = add_arr[i - 1] + arr[i];
        }
        System.out.println("原数组：" + Arrays.toString(arr));
        System.out.println("前缀和数组：" + Arrays.toString(add_arr));
        System.out.println("区间和：" + getSum(add_arr, 2, 5));
    }

    public static int getSum(int[] add_arr, int l, int r) {
        return add_arr[r] - add_arr[l - 1];
    }
}
